home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pcb51a.zip / SETMAIL.WAS < prev    next >
Text File  |  1992-09-20  |  13KB  |  406 lines

  1. ;SETMAIL.WAS v.5.1a - 9/20/92 06:41 AM
  2. ;Copyright (c) 1992, Gregg Hommel, All Rights Reserved
  3.  
  4. ; SETMAIL.WAS is a Windows Aspect script for use with ProComm Plus for
  5. ; Windows 1.01. It is used to set various parameters into an INI file.
  6. ; PCBMail can then read these parameters to set options when it is run.
  7.  
  8. integer rb1 = 1, source = 0, flag = 0, ndx=0, icondx=5, icondx2=41
  9. string pcblist = "(None)", name = "(None)", board, door, maildir, defconf
  10. string iconvar, iconvar2, pwfile, ren_def, dldir, pword, user, ini = "PCBMAIL.INI"
  11.  
  12. proc main
  13.    integer dlgstatus, button, lendx, charval
  14.    string del_set, save_set, wrong, user2, pword2
  15.    dialogbox 100 75 200 30 13
  16.       text 10 10 180 10 center "PCBMAIL setup is scanning for boards now."
  17.    enddialog
  18.    for ndx = 1 upto $DIALCOUNT
  19.       set dialdir access ndx
  20.       if strcmpi $D_SCRIPT "pcbmail"
  21.          strcat pcblist ","
  22.          strcat pcblist $D_NAME
  23.       endif
  24.    endfor
  25.  
  26. ; SETMAIL uses a section on the INI for board "(None)" to show sample
  27. ; settings in the dialog box. However, if this is the first time that
  28. ; SETMAIL has been run, or if the INI has been deleted, there will be no
  29. ; section, labelled [(None)]. If not, this creates it.
  30.  
  31.    profilerd ini name "board_id" board
  32.    if null_str(board)
  33.       set_none()
  34.    else
  35.       read_ini()
  36.    endif
  37.    pause 1
  38.    destroydlg
  39.    if strcmpi pcblist "(None)"
  40.       errormsg "There are no PCBMAIL systems in the dialing directory!"
  41.       exit
  42.    endif
  43.    pwfile=$PWTASKPATH
  44.    addfilename pwfile "PW.EXE"
  45.    iconvar="UserID"
  46.    iconvar2="Password"
  47.    dialogbox 80 45 245 186 13
  48.       groupbox 10 4 224 39 shadow
  49.       text  18 12 209 28 center "Use this dialog box to set the parameters which the PCBMAIL script needs to operate. The Join Conference? parameter is optional."
  50.       text  10 51 81 8 right "Select a PCBoard system :"
  51.       combobox 100 49 135 55 pcblist name sort
  52.       text  10 71 60 8 left "QWK filename?"
  53.       editbox 75 69 45 12 board 8
  54.       text  125 70 69 8 left "Mail door # (name)?"
  55.       editbox 195 68 40 13 door
  56.       text  10 91 60 8 left "Mail directory?"
  57.       editbox 75 89 50 12 maildir
  58.       text  130 91 60 8 left "Join Conference?"
  59.       editbox 195 89 40 12 defconf
  60.       groupbox 10 110 225 30 "Rename mail options"
  61.       radiobutton 20 122 100 10 "Standard format - QWA" rb1
  62.       radiobutton 130 122 100 10 "Alternate format - with date" endgroup
  63.       iconbutton 10 147 iconvar pwfile icondx 
  64.       iconbutton 40 147 iconvar2 pwfile icondx2 
  65.       pushbutton 76 153 40 14 "&Save" normal
  66.       pushbutton 134 153 41 14 "&Delete" normal
  67.       pushbutton 195 153 40 14 "E&xit" cancel
  68.    enddialog
  69.    disable ctrl 230 233
  70.    disable ctrl 210 211
  71.    disable ctrl 50
  72.    disable ctrl 10 11
  73.    dlgstatus = $DIALOG
  74.    while dlgstatus != 1
  75.       switch dlgstatus
  76.  
  77. ; case 170 handles the selection of a name from the drop down box
  78.  
  79.          case 170
  80.             if strcmpi name "(None)"
  81.                disable ctrl 230 233
  82.                disable ctrl 210 211
  83.                disable ctrl 50
  84.                disable ctrl 10 11
  85.                read_ini()
  86.                updatedlg 130
  87.             else
  88.                enable ctrl 230 233
  89.                enable ctrl 210 211
  90.                enable ctrl 50
  91.                enable ctrl 10 11
  92.                read_ini()
  93.                dialfind name ndx
  94.                set dialdir access ndx
  95.                fetch password pword
  96.                fetch userid user
  97.                updatedlg 130
  98.                if not null_str(maildir)
  99.                   source = 1
  100.                   chk_dir()
  101.                endif
  102.             endif
  103.          endcase
  104.  
  105. ; cases 210 and 211 handle a press of either icon in the dialog box
  106.  
  107.          case 210
  108.             user2=user
  109.             redo:
  110.             sdlginput "UserID" "Enter / Edit the UserID : " user DEFAULT
  111.             if success
  112.                if null_str(user)
  113.                   goto redo
  114.                endif
  115.                if not strcmpi user user2
  116.                   set userid user
  117.                   dialsave
  118.                endif
  119.             endif
  120.          endcase
  121.          case 211
  122.             pword2=pword
  123.             again:
  124.             sdlginput "Password" "Enter / Edit the Password : " pword DEFAULT
  125.             if success
  126.                if null_str(pword)
  127.                   goto again
  128.                endif
  129.                if not strcmpi pword pword2
  130.                   set password pword
  131.                   dialsave
  132.                endif
  133.          endif
  134.          endcase
  135.  
  136. ; case 10 takes care of saving the data set in the dialog box
  137.  
  138.         case 10
  139.         if not (null_str(user) || null_str(pword) || null_str(board) || null_str(door) || null_str(maildir))
  140.            strlen maildir lendx
  141.            lendx--
  142.            strpeek maildir lendx charval
  143.            if charval == 92
  144.               strdelete maildir lendx 1
  145.            endif
  146.            ren_def = $NULLSTR
  147.            if rb1 == 2
  148.               ren_def = "date"
  149.            endif
  150.            fetch dnldpath dldir
  151.            if null_str(ren_def)
  152.               same_dir()
  153.               if flag
  154.                  flag = 0
  155.                  exitswitch
  156.               endif
  157.             endif
  158.             source=2
  159.             chk_dir()
  160.             if flag
  161.                flag = 0
  162.                exitswitch
  163.             endif
  164.             strfmt save_set "Save configuration for %s?" name
  165.             sdlgmsgbox "Confirming..." save_set QUESTION YESNO button 1
  166.             if button == 6
  167.                strupr maildir
  168.                strupr board
  169.                strupr defconf
  170.                write_ini()
  171.                is_old_mail()
  172.                statmsg "Configuration for %s saved!" name
  173.                updatedlg 130
  174.             elseif button == 7
  175.                read_ini()
  176.                updatedlg 130
  177.             endif
  178.          else
  179.             wrong=$NULLSTR
  180.             if null_str(user)
  181.                wrong=str_make(wrong, "UserID")
  182.             endif
  183.             if null_str(pword)
  184.                wrong=str_make(wrong, "Password")
  185.             endif
  186.             if null_str(board)
  187.                wrong=str_make(wrong, "Qmail packet name")
  188.             endif
  189.             if null_str(door)
  190.                wrong=str_make(wrong, "Open door")
  191.             endif
  192.             if null_str(maildir)
  193.                wrong=str_make(wrong, "Mail directory")
  194.             endif
  195.             errormsg "Blank Field(s) are not allowed for - %s ." wrong
  196.          endif
  197.          endcase
  198.  
  199. ; case 11 performs a simple "delete" of a system from PCBMail, by removing
  200. ; all INI file settings. The system is not really deleted, but all entries
  201. ; in the INI are null.
  202.  
  203.          case 11
  204.             if not null_str(name)
  205.                strfmt del_set "Delete configuration for %s?" name
  206.                sdlgmsgbox "Confirming..." del_set STOP YESNO button 1
  207.                if button == 6
  208.                   if not null_str(board)
  209.                      board = $NULLSTR
  210.                      door = $NULLSTR
  211.                      maildir = $NULLSTR
  212.                      defconf = $NULLSTR
  213.                      ren_def = $NULLSTR
  214.                      write_ini()
  215.                      statmsg "Configuration for %s deleted!" name
  216.                      updatedlg 130
  217.                   else
  218.                      errormsg "%s is not configured!" name
  219.                   endif
  220.                endif
  221.             endif
  222.           endcase
  223.       endswitch
  224.       dlgstatus = $DIALOG
  225.    endwhile
  226. endproc
  227.  
  228. proc read_ini
  229.    profilerd ini name "board_ID" board
  230.    profilerd ini name "door_ID" door
  231.    profilerd ini name "mail_dir" maildir
  232.    profilerd ini name "def_conf" defconf
  233.    profilerd ini name "rename_as" ren_def
  234.    rb1 = 1
  235.    if not null_str(ren_def)
  236.       rb1 = 2
  237.    endif
  238. endproc
  239.  
  240. proc write_ini
  241.    profilewr ini name "board_ID" board
  242.    profilewr ini name "door_ID" door
  243.    profilewr ini name "mail_dir" maildir
  244.    profilewr ini name "def_conf" defconf
  245.    profilewr ini name "rename_as" ren_def
  246. endproc
  247.  
  248. ; This function may seem strange, since it does exactly what nullstr does,
  249. ; however, it does serve a purpose. Windows Aspect only allows the testing
  250. ; of a single nullstr command in an "if" conditional line. By using this
  251. ; function to replace it, I can test multiple strings for nulls, making the
  252. ; if...else conditionals simpler and faster.
  253.  
  254. func null_str:integer
  255.    strparm test_str
  256.    integer result
  257.    nullstr test_str result
  258.    return result
  259. endfunc
  260.  
  261. func str_make:string
  262.    strparm parm1, parm2
  263.    if not null_str(parm1)
  264.       strcat parm1 "; "
  265.    endif
  266.    strcat parm1 parm2
  267.    return parm1
  268. endfunc
  269.  
  270. ; Fairly straightforward.... if standard renaming is used, the mail
  271. ; directory and default download directory can not be the same. This proc
  272. ; justs checks for that.
  273.  
  274. proc same_dir
  275.    if strcmpi dldir maildir
  276.       errormsg "If standard renaming is used, the mail and download directories must be different!"
  277.       profilerd ini name "mail_dir" maildir
  278.       updatedlg 130
  279.       flag = 1
  280.    endif
  281. endproc
  282.  
  283. ; Again, fairly straightforward... check to see if the mail directory set
  284. ; in the dialog exists. If not, ask if the user wants it created.
  285.  
  286. proc chk_dir
  287.    integer button
  288.    string curr_dir, dirmsg
  289.    getdir 0 curr_dir
  290.    if not chdir maildir
  291.       if source == 1
  292.          mkdir maildir
  293.       elseif source == 2
  294.          strfmt dirmsg "The directory %s does not exist. Create it?" maildir
  295.          sdlgmsgbox "Warning!" dirmsg EXCLAMATION YESNO button 1 BEEP
  296.          if button == 6
  297.             mkdir maildir
  298.          elseif button == 7
  299.             flag = 1
  300.             profilerd ini name "mail_dir" maildir
  301.             updatedlg 130
  302.          endif
  303.       endif
  304.    endif
  305.    chdir curr_dir
  306. endproc
  307.  
  308. ; This proc is real fun stuff! <G> After we have saved the information for
  309. ; a system, check the download directory for old mail packets. If one (or
  310. ; more) is found, ask the user what to do with them... either delete them
  311. ; or rename them according to the settings in the dialog box. A whole bunch
  312. ; of steps just to do something that simple, huh?
  313.  
  314. proc is_old_mail
  315.    integer button, count, test = 0, char, char2, max = 0, ltr, len, rltr
  316.    string oldqwk, msg, newqwk, renqwk, oldfile, root, sdate
  317.    strfmt oldqwk "%s\%s.QW?" dldir board
  318.    if findfirst oldqwk
  319.       strfmt msg "Old mail for %s has been found. Rename it? [NO] will delete the old mail." name
  320.       sdlgmsgbox "Warning!" msg STOP YESNO button 1 BEEP
  321.       if button == 6
  322.          if null_str(ren_def)
  323.             root = board
  324.          else
  325.             substr sdate $DATE 0 5
  326.             strdelete sdate 2 1
  327.             strfmt root "%s%s" board sdate
  328.             strlen root len
  329.             if len > 8
  330.                len -= 8
  331.                strdelete root 4 len
  332.             endif
  333.          endif
  334.          strfmt newqwk "%s\%s.QW?" maildir root
  335.          if findfirst newqwk
  336.             max++
  337.             while 1
  338.                if findnext
  339.                   max++
  340.                else
  341.                   exitwhile
  342.                endif
  343.             endwhile
  344.          endif
  345.          max--
  346.          for count = 0 upto max
  347.             char = 65 + count
  348.             strfmt newqwk "%s\%s.qw%c" maildir root char
  349.             if findfirst newqwk
  350.                loopfor
  351.             else
  352.                for test upto 25
  353.                   char2 = char + test
  354.                   strfmt newqwk "%s\%s.qw%c" maildir root char2
  355.                   if findfirst newqwk
  356.                      strfmt renqwk "%s\%s.qw%c" maildir root char
  357.                      rename newqwk renqwk
  358.                      exitfor
  359.                   endif
  360.                endfor
  361.             endif
  362.          endfor
  363.          ltr = 65
  364.          rltr = max + 65
  365.          for count = 0 upto 35
  366.             strfmt oldqwk "%s\%s.QW%c" dldir board ltr
  367.             if isfile oldqwk
  368.                rltr++
  369.                strfmt renqwk "%s\%s.QW%c" maildir root rltr
  370.                rename oldqwk renqwk
  371.                if success
  372.                   statmsg "%s moved as %s.QW%c" oldfile root rltr
  373.                else
  374.                   statmsg "%s not moved!" oldqwk
  375.                endif
  376.             endif
  377.             if count == 25
  378.                ltr = 47
  379.             endif
  380.             ltr++
  381.          endfor
  382.       elseif button == 7
  383.          ltr = 65
  384.          for count = 0 upto 35
  385.             strfmt oldqwk "%s\%s.QW%c" dldir board ltr
  386.             if isfile oldqwk
  387.                delfile oldqwk
  388.             endif
  389.             if count == 25
  390.                ltr = 47
  391.             endif
  392.             ltr++
  393.          endfor
  394.       endif
  395.    endif
  396. endproc
  397.  
  398. proc set_none
  399.    board = "chanone"
  400.    door = "e.g. 15"
  401.    maildir = "X:\MAILDIR"
  402.    defconf = "e.g. 2"
  403.    write_ini()
  404. endproc
  405.  
  406.